#########################################################################
# File : /lua/system/stackvar.lua
# Description : Utility for storing boolean variable state as a stack
# Author : GPG
#########################################################################

StackVar = {
    Push = function(self) 
        self._val = self._val + 1
    end,
    
    Pop = function(self)
        self._val = self._val - 1
        if self._val < 0 then
            error("Mismatched StackVar push/pop")
        end
    end,
}

local svInstMeta = {
    __call = function(self,...)
        return self._val
    end,
}

local svClassMeta = {
    __call = function(self,...)
        local sv = table.copy(StackVar)
        sv._val = 0
        setmetatable(sv,svInstMeta)
        return sv
    end,
}

setmetatable(StackVar, svClassMeta)